package com.iwhalecloud.citybrain.flow.platform.manager.application.service.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import com.iwhalecloud.citybrain.flow.platform.manager.application.common.enums.EmbedOperateEnum;
import com.iwhalecloud.citybrain.flow.platform.manager.application.common.properties.EmbedOperateConfigProperties;
import com.iwhalecloud.citybrain.flow.platform.manager.application.service.EmbedOperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;

/**
 * @author lilh
 * @date 2021/4/7 09:36
 */
@Service
@EnableConfigurationProperties(EmbedOperateConfigProperties.class)
public class ApplyEmbedOperateServiceImpl implements EmbedOperateService {

    @Autowired
    private EmbedOperateConfigProperties embedProperties;

    @Override
    public EmbedOperateEnum getOperate() {
        return EmbedOperateEnum.APPLY;
    }

    @Override
    public void doOperate(HttpServletRequest request, HttpServletResponse response) throws Exception {
        String modelKey = request.getParameter("procDefKey");
        Assert.notBlank(modelKey, "参数缺失");
        // 获取重定向的地址
        String queryString = request.getQueryString();
        String url = embedProperties.getApplyUrl();
        if (StrUtil.isNotBlank(queryString)) {
            url = url + "?" + queryString;
        }
        //重定向
        response.sendRedirect(url);

    }
}
